package RKUjava.lang;

/** This class extends/improves the Double class defined by Sun. <br>
The main difference between Double and RKUNamedDouble is that RKUNamedDouble 
support setting the value of the wrapped <tt>double</tt>. The purpose of having a name
is to make it possible to make a lookup in e.g. anm array containing named doubles. <br>
The main use of the possiblility to set the value is the following. 
Suppose you have an double object referenced by many other
object and you want to change the value of the integer. This can't be done
with Suns Integer because it doesn't support setting the value.
<br><br>
<b> Implementation details:</b><br>
<ul>
<li>Since Suns Double class is final it can't be extended. Instead RKUNamedDouble
extends the RKUDouble class, which extends Suns Number class. 
</ul>
@author Rasmus K. Ursem, <a href="mailto:ursem@daimi.au.dk">ursem@daimi.au.dk</a>
*/
public class RKUNamedDouble extends RKUDouble
{

  /** The name of the named double.
    @serial
  */
  public String thename;

  public RKUNamedDouble(double value, String name)
    {
      super(value);
      thename = name;
    }

  /** Find a named double in an array. 
      @param array The array to search in.
      @param name The name to look for.
   @return The double if found or null if not found.
  */
  public static RKUNamedDouble findNamedDouble(RKUNamedDouble[] array, String name)
    {
      for (int i=0;i<array.length;i++) {
	if (array[i].thename.equals(name))
	  return array[i];
      }
      return null;
    }

  /** Find index of a named double in an array. 
      @param array The array to search in.
      @param name The name to look for.
   @return The index or -1 if not found.
  */
  public static int findIndexOfNamedDouble(RKUNamedDouble[] array, String name)
    {
      for (int i=0;i<array.length;i++) {
	if (array[i].thename.equals(name))
	  return i;
      }
      return -1;
    }

  public void setName(String name)
    {
      thename = name;
    }

  public String getName()
    {
      return thename;
    }

}





